package com.smartwebx.ha.web.admin.module.screen.role;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.dataresolver.Param;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.smartwebx.ha.biz.assign.HaRoleManager;
import com.smartwebx.ha.dal.assign.bean.HaRole;

public class AjaxAddRole {
	@Autowired
	private HaRoleManager haRoleManager;

	public void execute(@Param("data") String dateJson) throws Exception {
		ObjectMapper mapper = new ObjectMapper();
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
				false);
		HaRole role=mapper.readValue(dateJson, HaRole.class);
		if (role.getId() == null) {
			haRoleManager.addRole(role);
		} else {
			haRoleManager.updateRole(role);
		}	

	}
}
